﻿using B.MESUI.Login.BasicData_UI.BasicData;
using DevExpress.XtraEditors;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace B.MESUI.Login.BasicData_UI.Material
{
    public partial class AddMaterialForm : DevExpress.XtraEditors.XtraForm
    { 
        public delegate void AddMaterial();
        public event AddMaterial OnAddMaterial;
        public AddMaterialForm()
        {
            InitializeComponent();
        }

        private async void simpleButton1_Click(object sender, EventArgs e)
        {
            string url = $"http://localhost:5198/api/Material/Add";
            AddMaterialDTO data = new AddMaterialDTO()
            {
                MaterialCode = this.textEdit2.Text,
                MaterialName = this.textEdit1.Text,
                Spec = this.textEdit3.Text,
                Unit = this.comboBoxEdit1.Text,
                Remark = this.textEdit4.Text
            };
            string jsonData = JsonConvert.SerializeObject(data);
            string result = await BaseMethod.MethodsURL("post",url, jsonData);
            if (result != null)
            {
                MessageBox.Show("添加成功");
                OnAddMaterial.Invoke();
            }
            else
            {
                MessageBox.Show("添加失败");
            }
        }
    }
}